<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        console.dir(Object);
        // Object.defineProperty()

        let person = {
            firstName:'a',
            lastName:'b',
        }
        // Object.defineProperty直接在一个对象上定义了一个新属性，把定义的新属性可以直接返回
        Object.defineProperty(person,'fullName',{
            get(){
                return this.firstName + '-' + this.lastName;
            },
            set(value){
                console.log(value);
                // 当更改person中fullName属性时 就会触发set方法 value即更改过后的新值  劫持
                // 需求：将firstName  wushuo  lastName siguoyi
                let arr = value.split('-');
                this.firstName = arr[0];
                this.lastName = arr[1];

            }
        })
        console.log(person);
        person.lastName = 'xx';
        console.log(person);
        // 更改了fullName的值
        person.fullName = 'wushuo-siguoyi';

        let str = 'wushuo-siguoyi';
        console.log(str.split('-'));
    </script>
</body>
</html>